package com.futvan.z.job;

import com.futvan.z.erp.erp_account.Erp_accountService;
import com.futvan.z.erp.erp_account_detail.erp_account_detail;
import com.futvan.z.framework.core.z;
import com.futvan.z.framework.util.DateUtil;
import com.futvan.z.framework.util.SpringUtil;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;

import java.util.List;

/**
 * 清理失效账户记录
 */
public class ClearOvertimeAccJob implements StatefulJob {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //获取service
        Erp_accountService accservice = (Erp_accountService) SpringUtil.getBean("erp_accountService");

        //获取所有要失效的记录
        String sql = "select * from erp_account_detail ad  where ad.end_time IS NOT NULL AND ad.end_time<='"+ DateUtil.getDate() +"' and ad.balance>0 and ad.frozen=0";
        List<erp_account_detail> list = z.getSqlSession().selectList("erp_account_detail_select_sql",sql);
        for (erp_account_detail ad : list) {
            try {
                accservice.Subtract(ad.getUserid(),ad.getA_type(),ad.getBalance(),"0","9","");
            } catch (Exception e) {
                z.Error("清理失效账户记录出错："+ad.toString(),e);
            }
        }
    }
}
